package com.heima.freemarker.demo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

/**
 * @author itheima
 * @since 2022-07-04
 */
@Controller
public class HelloController {

    @GetMapping("/hello")
    public String hello(Model model) {
        //纯文本
        model.addAttribute("name", "张三");
        //实体类
        Map<String, Object> map = new HashMap<>();
        map.put("name", "李四");
        map.put("age", 18);
        model.addAttribute("stu", map);

        // 新增数据
        Map<String, Object> stu2 = new HashMap<>();
        stu2.put("name", "itheima");
        stu2.put("age", 16);

        // 新增集合
        List<Map<String, Object>> list = new ArrayList<>();
        list.add(map);
        list.add(stu2);

        model.addAttribute("stus", list);


        // 新增日期字段
        model.addAttribute("today", new Date());
        return "01-basic";
    }

}
